﻿Imports OMANE.Common.UI

Public Class ViewIndicateur

    Private Sub Button_Click_1(sender As Object, e As Windows.RoutedEventArgs)
        Dim builder = New ViewModelQueryBuilder()

        ModuleDashboarding._uiservice.ShowMessage(builder, Width:=600, Height:=400)
    End Sub

    Private Sub Button_Click_2(sender As Object, e As Windows.RoutedEventArgs)
        Dim txt = New Windows.Controls.TextBox
        txt.MinWidth = 200
        ModuleDashboarding._uiservice.ShowMessage(txt, "Nom de  la variable")
        Dim ind = New Indicateur()
        ind.Type = "Variable"
        ind.Name = Trim(txt.Text).ToLower()
        ModuleDashboarding._activeproject.IndicateurList.Add(ind)
    End Sub

    Private Sub Button_Click_3(sender As Object, e As Windows.RoutedEventArgs)
        Dim builder = New ViewModelIndicateurFormula()


        ModuleDashboarding._uiservice.ShowMessage(builder, Width:=600, Height:=400)

        If builder.Item("Name") = "" Then
            ModuleDashboarding._activeproject.IndicateurList.Add( _
                New Indicateur() With {.Name = builder.Name, .Type = "Formula", .Formula = builder.Formula, .XFormula = builder.GetExpression()})
        End If
    End Sub
End Class

Public Class ViewModelIndicateur
    Implements IViewModelTabSection




    Sub New()
        Title = "Indicateurs"

        Icone = StandardIcons.GRID
    End Sub
    Public Property Icone As String Implements IViewModelTabSection.Icone

    Public Property Title As String Implements IViewModelTabSection.Title

    Public ReadOnly Property IndicateurList As ObjectModel.ObservableCollection(Of Indicateur)
        Get
            Return ModuleDashboarding._activeproject.IndicateurList
        End Get
    End Property

    Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable
End Class

Public Class FilterTable
    Inherits UIObject

End Class



Public Class DoubleToBooleanConverter
    Implements Windows.Data.IValueConverter

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements Windows.Data.IValueConverter.Convert
        If value Is Nothing Then Return False
        If IsDBNull(value) Then Return False

        Return CDbl(value) = 1.0
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements Windows.Data.IValueConverter.ConvertBack
        If value Is Nothing Then Return 0.0

        Return If(CBool(value), 1.0, 0.0)
    End Function
End Class